#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "galois_add.h"
#include "galois.h"

main (int argc, char **argv)
{
	int i;
	uint64_t a, b, *tmp;
	unsigned char *x, *y, *test;
	unsigned char *q1, *q2, *z;
	x = (unsigned char *) malloc (sizeof(unsigned char) * 16);
	y = (unsigned char *) malloc (sizeof(unsigned char) * 16);
	test = (unsigned char *) malloc (sizeof(unsigned char) * 16);

	a =  lrand48();
	a <<= 32;
	a += lrand48();
	tmp = (uint64_t *) &x[0];
	*tmp = a;
	a =  lrand48();
	a <<= 32;
	a += lrand48();
	tmp = (uint64_t *) &x[8];
	*tmp = a;
	a =  lrand48();
	a <<= 32;
	a += lrand48();
	tmp = (uint64_t *) &y[0];
	*tmp = a;
	a =  lrand48();
	a <<= 32;
	a += lrand48();
	tmp = (uint64_t *) &y[8];
	*tmp = a;

	z = galois_shift_multiply_w128(x, y);
	q1 = galois_shift_divide_w128(z, y);
	q2 = galois_shift_divide_w128(z, x);

	// q1 == x
	// q2 == y

	for (i = 0; i < 16; i++) {
		test[i] = q1[i] ^ x[i];
		if (test[i] != 0) printf("Err\n");
	}
	for (i = 0; i < 16; i++) {
		test[i] = q2[i] ^ y[i];
		if (test[i] != 0) printf("Err\n");
	}
}
